#!/usr/bin/perl


use strict;
use Carp;

#include config file
use EP_UI_XML::Config;
use EP_DB::DB;

my $expire = time();

# get the sessions that have expired
my $sth_session = $Config::h->{DBH}->prepare( "select session_id from sessions_metadata where expire < ?");
my $rc_session = $sth_session->execute( $expire );
carp "[EP clean_session_data] No expired sessions\n" and exit if !$rc_session;

while ( my ($session_id) = $sth_session->fetchrow_array() ) {
    carp "[EP clean_session_data] Cleaning up $session_id\n" if $Config::h->{DEBUG} == 1;
    
    if ( &EP_DB::DB::remove_session_data( $session_id ) == 0 ) {
	carp "[EP clean_session_data] Session data not removed properly\n";
	next;
    }
    
    if ( &EP_DB::DB::remove_session( $session_id ) == 0 ) {
	carp "[EP clean_session_data] Session not removed properly\n";
	next;
    }
}
